﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#include "WallObject.h"
#include "WallObjectCustomizedSerialization.h"
#include "DbDataSchema.h"

#include "EnableCompileWarning_The_LAST_IncludeInCpp.h"

using namespace gcmp;
using namespace Sample;

static const Guid s_WallObjectClassGuid = { 0xEB606FFD, 0xACC2, 0x48E8, { 0xF4, 0x08, 0x2D, 0x08, 0x77, 0x17, 0x2C, 0x9E } };

Guid WallObject::GetClassGuid(void) const
{
    return s_WallObjectClassGuid;
}

WallObject::WallObject()
{
    SetName(L"test");
}

gcmp::ISerializationBehavior * WallObject::GetSerializationBehavior(void) const
{
    return WallObjectSerializationBehavior::Get(this);
}

gcmp::ICloneBehavior * WallObject::GetCloneBehavior(void) const
{
    return WallObjectCloneBehavior::Get(this);
}

gcmp::OwnerPtr<WallObject> WallObject::DeepCopy() const
{
    OwnerPtr<WallData> opNewData = NEW_AS_OWNER_PTR(WallData);
    opNewData->SetHeight(m_opData->GetHeight());
    opNewData->SetWidth(m_opData->GetWidth());
    opNewData->SetStart(m_opData->GetStartPoint());
    opNewData->SetEnd(m_opData->GetEndPoint());
    
    gcmp::OwnerPtr<WallObject> opCopied = NEW_AS_OWNER_PTR(WallObject);
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(opCopied.get(), L"opCopied为空", L"GDMP", L"2020/03/07");
    //opCopied->SetWall(m_pWall);
    opCopied->SetName(m_strName);
    opCopied->SetData(TransferOwnership(opNewData));
    return TransferOwnership(opCopied);
}

std::wstring WallObject::GetName() const
{
    return m_strName;
}

void WallObject::SetName(const std::wstring& szName)
{
    m_strName = szName;
}

const WallData* WallObject::GetData() const
{
    return m_opData.get();
}

WallData* WallObject::GetData()
{
    return m_opData.get();
}

void WallObject::SetData(OwnerPtr<WallData> opData)
{
    m_opData = TransferOwnership(opData);
}

REGISTER_UNSERIALIZATION_BEHAVIOR(s_WallObjectClassGuid, WallObjectUnserializationBehavior::Get())

